package com.wen.yygh.user.api;

import com.wen.yygh.common.result.Result;
import com.wen.yygh.common.util.AuthContextHolder;
import com.wen.yygh.model.user.Patient;
import com.wen.yygh.model.user.UserInfo;
import com.wen.yygh.user.service.PatientService;
import com.wen.yygh.user.service.UserService;
import com.wen.yygh.vo.user.LoginVo;
import com.wen.yygh.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/user")
@Api(tags = "用户登录")
@Slf4j
public class UserInfoApiController {
    @Autowired
    private UserService userService;
    @Autowired
    private PatientService patientService;

    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo) {
        Map<String, Object> result = userService.login(loginVo);
        return Result.ok(result);
    }

    @PostMapping("auth/userAuth")
    @ApiOperation("用户认证")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request) {
        userService.userAuth(AuthContextHolder.getUserId(request), userAuthVo);
        return Result.ok();
    }

    @GetMapping("auth/getUserInfo")
    @ApiOperation("获取用户详情")
    public Result getUserInfo(HttpServletRequest request) {
        log.info("token"+request.getHeader("token"));
        UserInfo info = userService.getById(AuthContextHolder.getUserId(request));
        return Result.ok(info);
    }


}
